# -*- coding: utf-8 -*-
# @Time    : 2019/12/13 11:37
# @Author  : Damn7Kx
# @Software: PyCharm
from solrcloudpy import SolrConnection

# 已知问题,使用solrcloudpy库会导致scrapy框架的日志打印失效

class Solr_Data(object):

    def __init__(self):
        self.conn = SolrConnection(server=['47.95.36.27:8983', '47.95.37.95:8984', '47.94.47.212:8985'],
                                   version="6.0.0", timeout=50)
        # 假设solrcloud中已经有solrtest这个collection，也可以用solrtest=conn['solrtest']
        self.solr_collection = self.conn['wenshupage']

    def add_docs(self,docs: dict):
        docs_list = [docs]
        try:
            self.solr_collection.add(docs_list)
            self.solr_collection.commit()
        except Exception as e:
            print('Solrcloud insert Except:',e)